<?php
/**
 * 返回格式化后金额（带单位）e.g.
 * 格式化规则：
 * price < 10000                        price+元                          6583元
 * 10000 <= price <100000000            round(price/10000,2)+万元         102.43万元
 * 100000000 <= price <PHP_INT_MAX      round(price/100000000,2)+亿元     1.03亿元
 * @param int $price
 * @param string $delimiter
 * @param int $is_return_str
 * @return string
 */
function price_format($price = 0,$delimiter='',$is_return_str=1)
{
    $unit_yuan = '元';
    $unit_wanyuan = '万元';
    $unit_yiyuan = '亿元';
    $i10000 = 10000;
    $i100000000 = 100000000;

    $price = intval($price);
    if ($price < $i10000) {
        $ret[] = $price;
        $ret[] = $unit_yuan;
    }elseif ($price >= $i10000 && $price < $i100000000) {
        $ret[] = round($price / $i10000, 2);
        $ret[] = $unit_wanyuan;
    }elseif ($price >= $i100000000 && $price < PHP_INT_MAX) {
        $ret[] = round($price / $i100000000, 2);
        $ret[] = $unit_yiyuan;
    } else {
        $ret[] = $price;
        $ret[] = $unit_yuan;
    }
    if ($is_return_str){
        return implode($delimiter,$ret);
    }else{
        $ret[] = $delimiter;
        return $ret;
    }

}

var_dump(price_format());
var_dump(price_format(6583));
var_dump(price_format(10000));
var_dump(price_format(10002));
var_dump(price_format(10024300));
var_dump(price_format(10202));
var_dump(price_format(100000000));
var_dump(price_format(100000022));
var_dump(price_format(103300000,'/',0));

var_dump(price_format(3.432423));
var_dump(price_format('1000,2223,2323..ddd'));
var_dump(price_format('-111'));